#include "MeasurE452AlgBackDatum.h"

MeasurE452AlgBackDatum::MeasurE452AlgBackDatum(int i):MeasurE452AlgBase(i)
{
}

void MeasurE452AlgBackDatum::operator()(cv::Mat &srcImg, int id)
{
    qDebug() << "start to E452 alg back datum";
    // back图   setup123   注意vector<cv::Point2f>& datum要转换到全局图像坐标系下
    std::vector<cv::Rect> rangVec1,rangVec2,rangVec3;

    if(srcImg.empty()) {
        Q_ASSERT(0);
    }

    TemplateMatch(srcImg,m_dataAllVec[41],rangVec1);
    TemplateMatch(srcImg,m_dataAllVec[42],rangVec2);
    TemplateMatch(srcImg,m_dataAllVec[43],rangVec3);

    std::vector<int> paras1,paras2,paras3;
    for(int j=0;j< m_dataAllVec[41].m_edgeParam.cols;j++)
    {
        paras1.push_back(m_dataAllVec[41].m_edgeParam.at<int>(0,j));
        paras2.push_back(m_dataAllVec[42].m_edgeParam.at<int>(1,j));
        paras3.push_back(m_dataAllVec[43].m_edgeParam.at<int>(2,j));
    }
    std::vector<cv::Point> contours1,contours2,contours3;
    std::vector<Point2f> datum;
    MeasurE452EdgeDetect obj;
    obj.GetLineContours(srcImg(rangVec1[0]).clone(), paras1, contours1);
    obj.GetLineContours(srcImg(rangVec2[0]).clone(), paras2, contours2);
    obj.GetLineContours(srcImg(rangVec3[0]).clone(), paras3, contours3);
    ImageCoordinateTransformation(contours1,rangVec1);
    ImageCoordinateTransformation(contours2,rangVec2);
    ImageCoordinateTransformation(contours3,rangVec3);
    std::move(contours2.begin(),contours2.end(), std::back_inserter(contours1));
    obj.GetDatum452(contours3,contours1,datum);

    MeasurE452AlgBase::datumBackVec[id]=datum;
    MeasurE452AlgBase::flagVec[id] = true;
    (*MeasurE452AlgBase::cvarptrVec[id]).notify_all();
    qDebug() << "end to E452 alg back datum";
}
